package com.closer.server.api.admin;

import com.closer.server.biz.problem.dto.AddRequest;
import com.closer.server.biz.problem.dto.JudgeCase;
import com.closer.server.biz.problem.dto.UpdateRequest;
import com.closer.server.biz.problem.dto.vo.AdminProblemVO;
import com.closer.server.biz.problem.dto.SearchByAdminRequest;
import com.closer.server.biz.problem.service.ProblemService;
import com.closer.server.support.common.BaseResponse;
import com.closer.server.support.common.ResultUtils;
import com.mybatisflex.core.paginate.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题目表 控制层。
 *
 * @author closer
 */
@RestController
@RequestMapping("/admin/problem")
public class AdminProblemController {

    private final ProblemService problemService;

    public AdminProblemController(ProblemService problemService) {
        this.problemService = problemService;
    }

    @PostMapping("/add")
    public BaseResponse<Long> add(@RequestBody AddRequest params) {
        var questionId = problemService.add(params);
        return ResultUtils.success(questionId);
    }

    @PostMapping("/update")
    public BaseResponse<Boolean> update(@RequestBody UpdateRequest params) {
        var result = problemService.updateProblem(params);
        return ResultUtils.success(result);
    }

    @PostMapping("/delete")
    public BaseResponse<Boolean> delete(@RequestParam Long id) {
        var result = problemService.delete(id);
        return ResultUtils.success(result);
    }

    @PostMapping("/search")
    public BaseResponse<Page<AdminProblemVO>> search(@RequestBody SearchByAdminRequest params) {
        var list = problemService.adminSearch(params);
        return ResultUtils.success(list);
    }

    @GetMapping("/get-case")
    public BaseResponse<List<JudgeCase>> getCase(@RequestParam Long id) {
        var list = problemService.getCase(id);
        return ResultUtils.success(list);
    }

}
